<template>
  <div class="content">
    <header>用户登录</header>

    <!-- 文本框 -->
    <ul class="login-form">
      <li>
        <div class="login-form-left">手机号码：</div>
        <div class="login-form-right">
          <input type="text" placeholder="手机号码" v-model="username" />
        </div>
      </li>
      <li>
        <div class="login-form-left">密码：</div>
        <div class="login-form-right">
          <input type="password" placeholder="密码" v-model="password" />
        </div>
      </li>
    </ul>

    <div class="login-button">
      <button @click="toLogin()">登录</button>
    </div>

    <div class="register-button">
      <button @click="toRegister()">去注册</button>
    </div>

    <Footer></Footer>
  </div>
</template>


<script>
import Footer from "../components/Footer";
export default {
  name: "Login",
  data() {
    return {
      username: "",
      password: "",
      flag: this.$route.query.flag
    };
  },
  methods: {
    toRegister() {
      this.$router.push("/register");
    },
    toLogin() {
      //校验非空
      if (this.username == "" || this.password == "") {
        alert("手机号或密码不能为空！");
        return;
      }
      //校验手机号格式

      //发送请求
      let url = `/LoginController/getUserByIdByPass/${this.username}/${this.password}`;
      this.$axios.get(url)
        .then(response => {
          let user = response.data.data;
          if (user == "" || user == null) {
            alert("用户名或密码错误！");
          } else {
            //存session
            this.$setSessionStorage("user", user);
            //返回上一页
            if (this.flag) {
              this.$router.go(-3);
            } else {
              this.$router.go(-1);
            }
          }
        })
        .catch(error => {
          console.log(error);
        });
    }
  },
  components: {
    Footer
  }
};
</script>


<style scoped>
/* 总容器 */
.content {
  width: 100%;
  height: 100%;
}
/* 头部 */
.content header {
  width: 100%;
  height: 12vw;
  background-color: #0097ff;
  font-size: 4.8vw;
  color: #fff;
  text-align: center;
  line-height: 12vw;
  position: fixed;
  top: 0vw;
  left: 0vw;
  z-index: 999;
}
.footer-top {
  width: 100%;
  height: 12vw;
}

/* 内容 */
.content .login-form {
  margin-top: 12vw;
}
.content .login-form li {
  box-sizing: border-box;
  padding: 4vw 3vw 0 3vw;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.content .login-form li .login-form-left {
  flex: 0 0 18vw;
  font-size: 3vw;
  font-weight: 700;
  color: #666;
}
.content .login-form li .login-form-right {
  flex: 1;
}
.content .login-form li .login-form-right input {
  border: none;
  outline: none; /* 表单元素去除焦点选中默认样式 */
  width: 100%;
  height: 4vw;
  font-size: 3vw;
}
.content .login-button {
  box-sizing: border-box;
  padding: 4vw 3vw 0 3vw;
}
.content .login-button button {
  width: 100%;
  height: 10vw;
  background-color: #38ca73;
  font-size: 3.8vw;
  font-weight: 700;
  border-radius: 4px;
  color: #fff;
  border: none;
  outline: none; /* 表单元素去除焦点选中默认样式 */
}
.content .register-button {
  box-sizing: border-box;
  padding: 4vw 3vw 0 3vw;
}
.content .register-button button {
  width: 100%;
  height: 10vw;
  background-color: #eee;
  font-size: 3.8vw;
  font-weight: 700;
  border-radius: 4px;
  color: #666;
  border: none;
  outline: none; /* 表单元素去除焦点选中默认样式 */
}
</style>